package com.starview.star.compiler.canonical;

import java.util.Map;

import com.starview.platform.data.type.IType;
import com.starview.platform.data.type.Location;
import com.starview.platform.data.type.Quantifier;
import com.starview.platform.data.type.TypeUtils;
import com.starview.star.compiler.util.GenSym;
import com.starview.star.compiler.util.Pair;

/**
 * Overloaded Variables have a type that includes contract dependencies. They must be handled
 * carefully; or they will blow up (fail to unify)
 * 
 * @author fgm
 * 
 */
@SuppressWarnings("serial")
public class OverloadedVariable extends Variable
{
  private final IType dictType;

  public OverloadedVariable(Location loc, IType type, IType dictType, String name)
  {
    super(loc, type, name);
    this.dictType = dictType;
  }

  public IType getDictType()
  {
    return dictType;
  }

  @Override
  public Variable copy()
  {
    return new OverloadedVariable(getLoc(), getType(), dictType, GenSym.genSym(getName()));
  }

  @Override
  public Variable underLoad()
  {
    return new Variable(getLoc(), getType(), getName());
  }

  @Override
  public boolean isRealVariable()
  {
    return false;
  }

  @Override
  public Pair<Variable, Map<String, Quantifier>> freshen(Location loc)
  {
    Pair<IType, Map<String, Quantifier>> f = TypeUtils.overloadedRefresh(dictType);

    return Pair.pair((Variable) new OverloadedVariable(loc, TypeUtils.getOverloadedType(f.left), f.left, getName()),
        f.right);
  }
}
